package com.atguigu.common.config.exception;

import com.atguigu.common.result.ResultCodeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * ClassName: GuiguException
 * Package: com.atguigu.common.config.exception
 * Description:
 *
 * 使用
 *  try{
 *      init i  = 10 / 0
 *  }catch(Exception e){
 *      throw new GuiguException(20001, "执行自定义异常处理“);
 *  }
 *
 * @Author: lmf
 * @Create: 2024/1/16 16:53
 * @Version: 1.0
 */



@Data
public class GuiguException extends RuntimeException {
    private Integer code;// 状态码
    private String message;// 错误信息

    public GuiguException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }


    /**
     * 接收枚举类型对象
     * @param resultCodeEnum code值
     */
    public GuiguException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
        this.message = resultCodeEnum.getMessage();
    }

    @Override
    public String toString() {
        return "GuliException{" +
                "code=" + code +
                ", message=" + this.getMessage() +
                '}';
    }
}
